package com.example.administrator.easy.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.easy.R;
import com.example.administrator.easy.detailxinfo.DetailVideoBean;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

/**
 * Created by jingsheng on 2016/11/15.
 */

public class DetailVideoAdapter extends BaseAdapter {//

    private Context context;
    private List<DetailVideoBean.ResultBean> list;
    private ImageOptions options;
    public DetailVideoAdapter(Context context, List<DetailVideoBean.ResultBean> list) {
        this.context = context;
        this.list = list;
    }


    @Override
    public int getCount() {
        Log.e("count",list.size()+"");
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        VideoViewHodler vh;
        options=new ImageOptions.Builder()
                .setCircular(true)
                .setLoadingDrawableId(R.mipmap.default_circle_img)
                .build();
        if (convertView==null){
            convertView=View.inflate(context,R.layout.detail_video_item,null);
            vh=new VideoViewHodler();
            vh.setView(convertView);
            convertView.setTag(vh);

        }else{
            vh= (VideoViewHodler) convertView.getTag();

        }

        vh.usetTv.setText(list.get(position).getUserNickName());
        x.image().bind(vh.userIv,list.get(position).getUserAvatar(),options);

        vh.tvcount.setText(list.get(position).getChatContent());


        if (list.get(position).getLiveAnnexList().size()>0){


            for (int i = 0; i < list.get(position).getLiveAnnexList().size(); i++) {

                    ImageView imageView=new ImageView(context);
                imageView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,180));
                    x.image().bind(imageView,list.get(position).getLiveAnnexList().get(i).getVideoCover());
                    vh.layoutBok.addView(imageView);

            }
        }

        return convertView;
    }
    class VideoViewHodler{

        private ImageView userIv;
        private LinearLayout layoutBok;
        private TextView usetTv,tvcount;

        private void setView(View view){
            userIv= (ImageView) view.findViewById(R.id.detail_video_uset_iv);
            layoutBok= (LinearLayout) view.findViewById(R.id.view_box_video);
            usetTv= (TextView) view.findViewById(R.id.detail_video_uset_tv);
            tvcount= (TextView) view.findViewById(R.id.video_tv_count);
        }
    }
}
